<script type="text/javascript">
	$(document).ready(function(){
    	$('select#id_stFD_space_type').change(function() {
    		var space_type = $(this).find("option:selected").text();
			$.ajax({
				type: "POST",
				url: '/pmp/scsetup/',
				data: JSON.stringify({'space_type':space_type, 'modelId':modelId,'ieqSpaceForm': $('form#ieqSpaceFD').serializeObject(), 'select':'changeSt'}),
				success: function(data){
					$('#setupInline').html(data)        
				}
			});
    	})
	})
	function addStInstance(){
		$.ajax({
			type: "POST",
			url: '/pmp/scsetup/',
			data: {'select': 'addSt', 'modelId': modelId},
			success: function(data){
				$('#setupInline').html(data)	        
			}
		});
	}
	function submitStInstance(){
		var space_type = $('#id_space_type').find("option:selected").text();
		$.ajax({
			type: "POST",
			url: '/pmp/scsetup/',
			data: JSON.stringify({'modelId': modelId, 'select': 'submitSt','stForm': $('form#stForm').serializeObject(), 'ieqSpaceForm': $('form#ieqSpaceFD').serializeObject(), 'space_type':space_type}),
			success: function(data){
				$('#setupInline').html(data)
				$('#success').fadeIn().delay(2000).fadeOut(1000);    
			}
		});
	}
	function deleteStInstance(){
		var space_type = $('#id_space_type').find("option:selected").text();
		$.ajax({
			type: "POST",
			url: '/pmp/scsetup/',
			data: {'modelId': modelId, 'select': 'deleteSt', 'space_type':space_type},
			success: function(data){
				$('#setupInline').html(data)
				$('#success').fadeIn().delay(2000).fadeOut(1000);    
			}
		});
	}
</script>

<form id='ieqSpaceFD' class="form-inline">
	<label class="control-label">IEQ Model Space Definition: &nbsp;</label>
	{{ ieq_space.management_form }}
	{{ ieq_space.space_type }}&nbsp;<input type="image" src="/static/admin/img/icon_addlink.gif" width="10" height="10" alt="Add Another" onclick="addStInstance(); return false;">
</form>
{% if stModel %}
{% load widget_tweaks %}
{{ stModel.management_form }}
<hr>
<div id="stInline">
<form id="stForm">
Space type: &nbsp;{{stModel.space_type}}<br>
Summer start month: &nbsp;{{stModel.summer_start_month|add_class:"span1"}}{{stModel.summer_start_month.errors}}<br>
Summer end month: &nbsp;{{stModel.summer_end_month|add_class:"span1"}}{{stModel.summer_end_month.errors}}<br>
Space type weight: &nbsp;{{stModel.weight|add_class:"span1"}}{{stModel.weight.errors}}
<br>
<table class="table table-hover">
	<thead>
		<th></th>
		<th>Class 1</th>
		<th>Class 2</th>
		<th>Class 3</th>
		<th>Class 4</th>
		<th>Class 5</th>
	</thead>
	<tbody>
	<tr>
		<td colspan="6" style="font-weight: bold">Thermal Comfort</td>
	</tr>
	<tr>
		<td>Summer lower condition</td>
		<td>{{stModel.qc1_tc_summer_condition_low|add_class:"span1"}}{{stModel.qc1_tc_summer_condition_low.errors}}</td>
		<td>{{stModel.qc2_tc_summer_condition_low|add_class:"span1"}}{{stModel.qc2_tc_summer_condition_low.errors}}</td>
		<td>{{stModel.qc3_tc_summer_condition_low|add_class:"span1"}}{{stModel.qc3_tc_summer_condition_low.errors}}</td>
		<td>{{stModel.qc4_tc_summer_condition_low|add_class:"span1"}}{{stModel.qc4_tc_summer_condition_low.errors}}</td>
		<td>{{stModel.qc5_tc_summer_condition_low|add_class:"span1"}}{{stModel.qc5_tc_summer_condition_low.errors}}</td>
	</tr>
	<tr>
		<td>Summer upper condition</td>
		<td>{{stModel.qc1_tc_summer_condition_high|add_class:"span1"}}{{stModel.qc1_tc_summer_condition_high.errors}}</td>
		<td>{{stModel.qc2_tc_summer_condition_high|add_class:"span1"}}{{stModel.qc2_tc_summer_condition_high.errors}}</td>
		<td>{{stModel.qc3_tc_summer_condition_high|add_class:"span1"}}{{stModel.qc3_tc_summer_condition_high.errors}}</td>
		<td>{{stModel.qc4_tc_summer_condition_high|add_class:"span1"}}{{stModel.qc4_tc_summer_condition_high.errors}}</td>
		<td>{{stModel.qc5_tc_summer_condition_high|add_class:"span1"}}{{stModel.qc5_tc_summer_condition_high.errors}}</td>
	</tr>
	<tr>
		<td>Winter lower condition</td>
		<td>{{stModel.qc1_tc_winter_condition_low|add_class:"span1"}}{{stModel.qc1_tc_winter_condition_low.errors}}</td>
		<td>{{stModel.qc2_tc_winter_condition_low|add_class:"span1"}}{{stModel.qc2_tc_winter_condition_low.errors}}</td>
		<td>{{stModel.qc3_tc_winter_condition_low|add_class:"span1"}}{{stModel.qc3_tc_winter_condition_low.errors}}</td>
		<td>{{stModel.qc4_tc_winter_condition_low|add_class:"span1"}}{{stModel.qc4_tc_winter_condition_low.errors}}</td>
		<td>{{stModel.qc5_tc_winter_condition_low|add_class:"span1"}}{{stModel.qc5_tc_winter_condition_low.errors}}</td>
	</tr>
	<tr>
		<td>Winter upper condition</td>
		<td>{{stModel.qc1_tc_winter_condition_high|add_class:"span1"}}{{stModel.qc1_tc_winter_condition_high.errors}}</td>
		<td>{{stModel.qc2_tc_winter_condition_high|add_class:"span1"}}{{stModel.qc2_tc_winter_condition_high.errors}}</td>
		<td>{{stModel.qc3_tc_winter_condition_high|add_class:"span1"}}{{stModel.qc3_tc_winter_condition_high.errors}}</td>
		<td>{{stModel.qc4_tc_winter_condition_high|add_class:"span1"}}{{stModel.qc4_tc_winter_condition_high.errors}}</td>
		<td>{{stModel.qc5_tc_winter_condition_high|add_class:"span1"}}{{stModel.qc5_tc_winter_condition_high.errors}}</td>
	</tr>
	<tr>
		<td>Units or type of measurement (for all classes)</td>
		<td colspan="5">{{stModel.units_tc|add_class:"span2"}}{{stModel.units_tc.errors}}</td>
	</tr>
	<tr>
		<td colspan="6" style="font-weight: bold">Indoor Air Quality</td>
	</tr>
	<tr>
		<td>IAQ lower condition</td>
		<td>{{stModel.qc1_iaq_condition_low|add_class:"span1"}}{{stModel.qc1_iaq_condition_low.errors}}</td>
		<td>{{stModel.qc2_iaq_condition_low|add_class:"span1"}}{{stModel.qc2_iaq_condition_low.errors}}</td>
		<td>{{stModel.qc3_iaq_condition_low|add_class:"span1"}}{{stModel.qc3_iaq_condition_low.errors}}</td>
		<td>{{stModel.qc4_iaq_condition_low|add_class:"span1"}}{{stModel.qc4_iaq_condition_low.errors}}</td>
		<td>{{stModel.qc5_iaq_condition_low|add_class:"span1"}}{{stModel.qc5_iaq_condition_low.errors}}</td>
	</tr>
	<tr>
		<td>IAQ upper condition</td>
		<td>{{stModel.qc1_iaq_condition_high|add_class:"span1"}}{{stModel.qc1_iaq_condition_high.errors}}</td>
		<td>{{stModel.qc2_iaq_condition_high|add_class:"span1"}}{{stModel.qc2_iaq_condition_high.errors}}</td>
		<td>{{stModel.qc3_iaq_condition_high|add_class:"span1"}}{{stModel.qc3_iaq_condition_high.errors}}</td>
		<td>{{stModel.qc4_iaq_condition_high|add_class:"span1"}}{{stModel.qc4_iaq_condition_high.errors}}</td>
		<td>{{stModel.qc5_iaq_condition_high|add_class:"span1"}}{{stModel.qc5_iaq_condition_high.errors}}</td>
	</tr>
	<tr>
		<td>Units or type of measurement (for all classes)</td>
		<td colspan="5">{{stModel.units_iaq|add_class:"span2"}}{{stModel.units_tc.errors}}</td>
	</tr>
	<tr>
		<td colspan="6" style="font-weight: bold">Lighting</td>
	</tr>
	<tr>
		<td>Lighting lower condition</td>
		<td>{{stModel.qc1_lighting_condition_low|add_class:"span1"}}{{stModel.qc1_lighting_condition_low.errors}}</td>
		<td>{{stModel.qc2_lighting_condition_low|add_class:"span1"}}{{stModel.qc2_lighting_condition_low.errors}}</td>
		<td>{{stModel.qc3_lighting_condition_low|add_class:"span1"}}{{stModel.qc3_lighting_condition_low.errors}}</td>
		<td>{{stModel.qc4_lighting_condition_low|add_class:"span1"}}{{stModel.qc4_lighting_condition_low.errors}}</td>
		<td>{{stModel.qc5_lighting_condition_low|add_class:"span1"}}{{stModel.qc5_lighting_condition_low.errors}}</td>
	</tr>
	<tr>
		<td>Lighting upper condition</td>
		<td>{{stModel.qc1_lighting_condition_high|add_class:"span1"}}{{stModel.qc1_lighting_condition_high.errors}}</td>
		<td>{{stModel.qc2_lighting_condition_high|add_class:"span1"}}{{stModel.qc2_lighting_condition_high.errors}}</td>
		<td>{{stModel.qc3_lighting_condition_high|add_class:"span1"}}{{stModel.qc3_lighting_condition_high.errors}}</td>
		<td>{{stModel.qc4_lighting_condition_high|add_class:"span1"}}{{stModel.qc4_lighting_condition_high.errors}}</td>
		<td>{{stModel.qc5_lighting_condition_high|add_class:"span1"}}{{stModel.qc5_lighting_condition_high.errors}}</td>
	</tr>
	<tr>
		<td>Units or type of measurement (for all classes)</td>
		<td colspan="5">{{stModel.units_lighting|add_class:"span2"}}{{stModel.units_tc.errors}}</td>
	</tr>
	<tr>
		<td colspan="6" style="font-weight: bold">Acoustics</td>
	</tr>
	<tr>
		<td>Acoustics lower condition</td>
		<td>{{stModel.qc1_acc_condition_low|add_class:"span1"}}{{stModel.qc1_acc_condition_low.errors}}</td>
		<td>{{stModel.qc2_acc_condition_low|add_class:"span1"}}{{stModel.qc2_acc_condition_low.errors}}</td>
		<td>{{stModel.qc3_acc_condition_low|add_class:"span1"}}{{stModel.qc3_acc_condition_low.errors}}</td>
		<td>{{stModel.qc4_acc_condition_low|add_class:"span1"}}{{stModel.qc4_acc_condition_low.errors}}</td>
		<td>{{stModel.qc5_acc_condition_low|add_class:"span1"}}{{stModel.qc5_acc_condition_low.errors}}</td>
	</tr>
	<tr>
		<td>Acoustics upper condition</td>
		<td>{{stModel.qc1_acc_condition_high|add_class:"span1"}}{{stModel.qc1_acc_condition_high.errors}}</td>
		<td>{{stModel.qc2_acc_condition_high|add_class:"span1"}}{{stModel.qc2_acc_condition_high.errors}}</td>
		<td>{{stModel.qc3_acc_condition_high|add_class:"span1"}}{{stModel.qc3_acc_condition_high.errors}}</td>
		<td>{{stModel.qc4_acc_condition_high|add_class:"span1"}}{{stModel.qc4_acc_condition_high.errors}}</td>
		<td>{{stModel.qc5_acc_condition_high|add_class:"span1"}}{{stModel.qc5_acc_condition_high.errors}}</td>
	</tr>
	<tr>
		<td>Units or type of measurement (for all classes)</td>
		<td colspan="5">{{stModel.units_acc|add_class:"span2"}}{{stModel.units_tc.errors}}</td>
	</tr>
	</tbody>
</table>
	<p style="margin-top: 5px"><input type="submit" class="btn" value="Save" onclick="submitStInstance(); return false;"/>
		<input type="submit" class="btn" value="Cancel" onclick="addStInstance(); return false;"/>
		<input type="submit" class="btn" value="Delete" onclick="deleteStInstance(); return false;"/>
		<span id="success"><strong>&nbsp;&nbsp;{{ saveStatus }}</strong></span>
	</p>
</form>
</div>
{% endif %}
